package com.awspaas.user.apps.shhtaerospaceindustrial.apartmanage;

import java.util.List;
import java.util.Map;

import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListener;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListenerInterface;
import com.actionsoft.bpms.commons.database.ColumnMapRowMapper;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.exception.BPMNError;
import com.awspaas.user.apps.shhtaerospaceindustrial.util.CoreUtil;

public class checkMessageChange extends InterruptListener  implements InterruptListenerInterface{


	public String getDescription() {
		return "申请人提交时，提醒家属信息变更信息是否填写正确！";
	}
	
	public String getProvider() {
		return "Actionsoft";
	}
	
	public String getVersion() {
		return "1.0";
	}
	
	@Override
	public boolean execute(ProcessExecutionContext param) throws Exception {
		//获取流程实例ID
		String processInstId = param.getProcessInstance().getId();
		//根据流程实例ID获取任务表内数据
		List<Map<String , Object>> bodylist = DBSql.query("SELECT * FROM BO_EU_SH_MESSAGECHANGE_B  WHERE BINDID = ? ", 
				new ColumnMapRowMapper(), new Object[] {processInstId});
		if(bodylist == null || bodylist.isEmpty()) {
			throw new BPMNError("未填写家属信息变更子表信息，请填写完毕内容后在提交！");
		}else {
			for (int i = 0; i < bodylist.size(); i++) {
				Map<String , Object> dataprobleminvent = bodylist.get(i);
				String CHANGETYPE = CoreUtil.objToStr(dataprobleminvent.get("CHANGETYPE"));// 变更类型修改|增加|删除
				String FID = CoreUtil.objToStr(dataprobleminvent.get("FID"));// 父id,租赁信息表id
				if("修改".equals(CHANGETYPE) && "".equals(FID)) {
					throw new BPMNError("您选择的变更类型为："+CHANGETYPE+"，请选择原有家属信息基础上修改信息！");
				}else if("删除".equals(CHANGETYPE) && "".equals(FID)) {
					throw new BPMNError("您选择的变更类型为："+CHANGETYPE+"，请选择原有家属信息！");
				}
			}
		}
		return true;
	}
}
